import os
import sys
from collections import defaultdict
import math
# 请在此输入您的代码
input = lambda: sys.stdin.readline().strip()
n,m = map(int,input().split())
board = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(n):
    board[_] = list(map(int,input().split()))

hashmap = defaultdict(int)
# (dir,x+y,val):point
for i in range(n):
  for j in range(m):
    hashmap[('0',i-j,board[i][j])]+=1
    hashmap[('1',i+j,board[i][j])]+=1

result = 0
for i,val in hashmap.items():
   if val >= 2:
      result += math.factorial(val)//math.factorial(val-2)
print(result)